package com.jiantong.user.impl.service;


import com.jiantong.user.impl.dao.SysModulesDao;
import com.google.common.base.Throwables;
import com.jiantong.user.model.SysModules;
import com.jiantong.user.service.SysModuleReadService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by ThinkPad on 2017/8/8.
 */
@Slf4j
@Service
@RpcProvider
public class SysModuleReadServiceImpl implements SysModuleReadService {

    private final SysModulesDao sysModulesDao;

    @Autowired
    public SysModuleReadServiceImpl(SysModulesDao sysModulesDao) {
        this.sysModulesDao = sysModulesDao;
    }

    @Override
    public Response<List<SysModules>> SelectAll(Map map) {
        return Response.ok(sysModulesDao.list(map));
    }

    @Override
    public Response<List<SysModules>> selectTop() {
        try{
            return Response.ok(sysModulesDao.selectTop());
        }catch (Exception e){
            log.error("failed to find SysModules list ", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to find SysModules list");
        }
    }

    @Override
    public Response<List<SysModules>> selectChild(Map criteria) {
        try{
            return Response.ok(sysModulesDao.selectChild(criteria));
        }catch (Exception e){
            log.error("failed to find SysModules list ", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to find SysModules list");
        }
    }

    @Override
    public Response<List<SysModules>> selectFirst(Map criteria) {
        try{
            return Response.ok(sysModulesDao.selectFirst(criteria));
        }catch (Exception e){
            log.error("failed to find SysModules list ", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to find SysModules list");
        }
    }
}
